package com.foreknow.hospital.controller;

import com.foreknow.hospital.po.Users;
import com.foreknow.hospital.service.UsersService;
import com.foreknow.hospital.service.impl.UsersServiceImpl;

import javax.servlet.http.HttpServletRequest;

public class UsersController {
    public Object saveUsers(HttpServletRequest request) {
        UsersService usersService = new UsersServiceImpl();
        Users users = new Users();
        users.setUserId(request.getParameter("userId"));
        users.setRealName(request.getParameter("realName"));
        users.setPassword(request.getParameter("password"));
        users.setSex(Integer.parseInt(request.getParameter("sex")));
        users.setIdentityCard(request.getParameter("identityCard"));
        users.setBirthday(request.getParameter("birthday"));
        users.setUserType(Integer.parseInt(request.getParameter("userType")));
        int result = usersService.saveUsers(users);
        return result;
    }

    /**
     * 根据用户编号查询用户表返回的行数
     * http://localhost:8081/elm/UsersController/getUsersByUserIdByPass?userId=1234561111
     * @param reuqest
     * @return
     */
    public Object getUsersById(HttpServletRequest reuqest) {
        UsersService usersService = new UsersServiceImpl();
        int count = usersService.getUsersById(reuqest.getParameter("userId"));
        return count;
    }

    /**
     * http://localhost:8081/elm/UserController/getUsersByUserIdByPass?userId=12345671111&password=123
     * @param request
     * @return
     */
    public Object getUsersByUserIdByPass(HttpServletRequest request) {
        UsersService usersService = new UsersServiceImpl();
        String userId = request.getParameter("userId");
        String password = request.getParameter("password");
        Users users = usersService.getUsersByUserIdByPass(userId,password);
        return users;
    }
}
